import { showLoading, hideLoading } from '../register/globalFun'
/**
 * url参数解析
 * @param url 地址
 */
export const resolveUrl = (url:string = location.href) => {
  const data:{[key:string]: string} = {}
  const str:string = url.split('?')[ 1 ]

  if (str) {
    str.split('&').forEach((item:string) => {
      const splitParam:string[] = item.split('=')

      data[ splitParam[ 0 ] ] = splitParam[ 1 ]
    })
  }
  return data
}

/**
 * loading回调
 */
export const loadingFn = async(fn: ()=>void, text?:string) => {
  try {
    showLoading(text)
    await fn()
  } catch (err) {
    return Promise.reject(err)
  }
  hideLoading()
}
